package <%= controllerPackageName %>;

import <%= servicePackageName %>.<%= camelCaseName(tableName,true) %>Service;
import <%= domainPackageName %>.<%= camelCaseName(tableName,true) %>;
import <%= utilsPackageName %>.BaseController;
import <%= utilsPackageName %>.CamelMap;
import <%= utilsPackageName %>.PageJpa;
import <%= utilsPackageName %>.PageMybatis;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author 代码生成器@zhangQ
 * @date <%= formatTime() %>
 */
@RestController
@RequestMapping("<%=camelCaseName(tableName,true)%>")
@Api(value = "<%=camelCaseName(tableName,true)%>", description = "<%=tableComment %> 控制器")
public class <%= camelCaseName(tableName,true) %>Controller extends BaseController {
    @Autowired
    private <%= camelCaseName(tableName,true) %>Service <%= camelCaseName(tableName) %>Service;

    /**
     * @return <%= camelCaseName(tableName,true) %>
     * @author 代码生成器@zhangQ
     * @date <%= formatTime() %>
     */
    @ApiOperation(value = "添加实例<%= camelCaseName(tableName,true) %>", notes = "添加实例<%= camelCaseName(tableName,true) %>")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "<%= camelCaseName(tableName) %>", value = "<%= camelCaseName(tableName,true) %>实体", dataType = "<%= camelCaseName(tableName,true) %>")
    })
    @RequestMapping(value = "saveEntity", method = RequestMethod.POST)
    public <%= camelCaseName(tableName,true) %> saveEntity(@RequestBody <%= camelCaseName(tableName,true) %> <%= camelCaseName(tableName) %>) {
        return <%= camelCaseName(tableName) %>Service.saveEntity(<%= camelCaseName(tableName) %>);
    }

<% if(existsField(table.columns,'state')) { -%>
    /**
     * @return Integer
     * @author 代码生成器@zhangQ
     * @date <%= formatTime() %>
     */
    @ApiOperation(value = "修改实例<%= camelCaseName(tableName,true) %>状态", notes = "修改实例<%= camelCaseName(tableName,true) %>状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "<%= table.primaryKeys[0].name %>", value = "<%= camelCaseName(tableName,true) %>的id", dataType = "<%= table.primaryKeys[0].type %>"),
            @ApiImplicitParam(name = "state", value = "状态码", dataType = "Integer")
    })
    @RequestMapping(value = "<%=camelCaseName(tableName)%>ModifyState", method = RequestMethod.POST)
    public Integer <%=camelCaseName(tableName)%>ModifyState(<%= table.primaryKeys[0].type %> <%= table.primaryKeys[0].name %>, Integer state) {
        if (state == null) {
            state = 99;
        }
        return <%= camelCaseName(tableName) %>Service.<%=camelCaseName(tableName)%>ModifyState(<%= table.primaryKeys[0].name %>, state);
    }
<% } -%>

    /**
     * @return
     * @author 代码生成器@zhangQ
     * @date <%= formatTime() %>
     */
    @ApiOperation(value = "Jpa分页获取<%= camelCaseName(tableName,true) %>列表", notes = "Jpa分页获取<%= camelCaseName(tableName,true) %>列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "PageJpa对象", dataType = "PageJpa")
    })
    @RequestMapping(value = "query<%= camelCaseName(tableName,true) %>ByPage", method = RequestMethod.POST)
    public PageJpa query<%= camelCaseName(tableName,true) %>ByPage(@RequestBody PageJpa page) {
        return <%= camelCaseName(tableName) %>Service.query<%= camelCaseName(tableName,true) %>ByPage(page);
    }

    /**
     * @return
     * @author 代码生成器@zhangQ
     * @date <%= formatTime() %>
     */
    @ApiOperation(value = "mybatis分页查询列表", notes = "mybatis分页查询列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "PageMybatis对象", dataType = "PageMybatis")
    })
    @RequestMapping(value = "queryMapByPage", method = RequestMethod.POST)
    public PageMybatis queryMapByPage(PageMybatis page) {
        return <%= camelCaseName(tableName) %>Service.queryMapByPage(page);
    }

}